package io.gitee.chearnee.fw.web.config;

import com.baomidou.mybatisplus.annotation.DbType;
import com.baomidou.mybatisplus.extension.plugins.inner.InnerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.inner.PaginationInnerInterceptor;
import io.gitee.chearnee.fw.common.component.converter.StringToBaseEnumConverterFactory;
import io.gitee.chearnee.fw.common.component.converter.StringToLocalDateTimeConverter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.convert.converter.ConverterRegistry;

/**
 * @author cn
 * @version 1.0
 * @description
 * @date 2022/5/10 17:47
 */
@Configuration(proxyBeanMethods = false)
public class FWConfig {
    @Bean
    public StringToLocalDateTimeConverter stringToLocalDateTimeConverter() {
        return new StringToLocalDateTimeConverter();
    }

    @Bean
    public ConverterRegistry converterRegistry(ConverterRegistry a) {
        a.addConverterFactory(new StringToBaseEnumConverterFactory());
        return a;
    }

    @Configuration(proxyBeanMethods = false)
    @ConditionalOnBean({InnerInterceptor.class})
    public static class MybatisPlusInterceptorConfiguration {

        @Bean
        public PaginationInnerInterceptor paginationInnerInterceptor() {
            return new PaginationInnerInterceptor(DbType.MYSQL);
        }

    }
}
